﻿@model XPressify.Models.ProfileFriendListModel
@using Omu.Awesome.Core;
@using Omu.Awesome.Mvc.Helpers;
@using XPressify.Controllers

@{
    ViewBag.Title = "Friend list";
}

<script type="text/javascript">

    var searchValue = $('#search').val();
    $(function () {
        setTimeout(checkSearchChanged, 0.1);
    });

    function checkSearchChanged() {
        var currentValue = $('#search').val();
        if ((currentValue) && currentValue != '' && currentValue != searchValue) { /*   if (currentValue != searchValue)    */
            searchValue = $('#search').val();
            $('#submit').submit();
        }
        else {
            setTimeout(checkSearchChanged, 0.1);
        }
    }

    $(document).ready(function () {
        $('#ui-tabs-3').css('font', '13px "Trebuchet MS", Verdana, Helvetica, sans-serif');
    });
    
</script>

@if (Model.IsOwner)
{
    
    <div>
        @(Html.MakePopupForm<ProfileController>(o => o.FriendListDelete(Model.OwnerUserId), title: "Delete friends", height: 350, width: 400, okText: "Delete", resizable: false, refreshOnSuccess: true))
        @(Html.PopupFormActionLink<ProfileController>(o => o.FriendListDelete(Model.OwnerUserId), "Delete friends", new { @class = "nobtn" ,style="color:blue"}))
    </div>
    <br />
}


@using (Ajax.BeginForm("SearchResults", new AjaxOptions { UpdateTargetId = "searchResults", OnSuccess = "checkSearchChanged", InsertionMode = System.Web.Mvc.Ajax.InsertionMode.Replace, HttpMethod = "POST" }))
{
    <input type="hidden" value="@Model.Id" name="id" />
    @Html.TextBox("search", null, new { }) 
    <input id="submit" type="submit" value="Search" />
}

<div id="searchResults">

    <table border="0">
    <tr>
        <th width="50px"></th>
        <th></th>
        <th></th>
    </tr>

    @foreach (var allFriend in Model.AllFriends)
    {
        <tr>
            <td >
                <a href='@Url.Action("ProfileView", "Profile", new { id = allFriend.Id })' class="nobtn">
                    <img src= "@allFriend.ProfilePicturePath" alt="Profile picture" title="Profile picture" style="width: 50px;height: 50px;" />
                </a>
            </td>
            <td>
                @Html.ActionLink(allFriend.FullName, "ProfileView", "Profile", new { id = allFriend.Id }, new { @class = "nobtn" , style="color:blue"})
            </td>
            <td style="text-align:right">
                @if (allFriend.ConfirmFriend)
                {
                    @Html.ActionLink("Confirm friend", "ConfirmRelationship", "User", new { Id = allFriend.Id }, new { @class = "abtn" }) 
                }
                else if (allFriend.ConfirmFriend == false && allFriend.AddFriend == true)
                {
                    @Html.ActionLink("Add as a friend", "AddFriend", "User", new { Id = allFriend.Id }, new { @class = "abtn" })
                }
            </td>
        </tr>
    }
    </table>
</div>